<template>
  <div class="post_son_comment">
    <!-- 子评论内容 -->
    <div class="comment_content">
      <div class="comment_writer">
        <div class="writer">
          <div class="admin">{{parentComment.account.nickname}}</div>
          <div class="date">{{parentComment.updated_at | formatTime}}</div>
          <!-- <div class="time">03:35</div> -->
        </div>
        <div class="floor">{{parentComment.level}}楼</div>
      </div>
      <!-- 在组件内部自己调用自己 实现递归 -->
      <postComment
        @sendReply="handlerReply(parentComment.id,parentComment.account.nickname)"
        :parentComment="parentComment.parent"
        v-if="parentComment.parent"
      />
      <div class="post_comment_content">
        <div class="content">{{parentComment.content}}</div>
        <div class="img" v-if="parentComment.pics.length>0">
          <span class="imgItem" v-for="(v,i) of parentComment.pics" :key="i">
            <img :src="$axios.defaults.baseURL+v.url" alt />
          </span>
        </div>
        <div class="clearfix">
          <span
            class="button"
            @click="handlerReply(parentComment.id,parentComment.account.nickname)"
          >回复</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import moment from "moment";
export default {
  name: "postComment",
  directives: {
    focus: {
      inserted: function (el) {
        el.focus();
      },
    },
  },
  filters: {
    // 时间戳过滤器
    formatTime(val) {
      let res = moment(val).format("YYYY-MM-DD hh:mm:ss");
      return res;
    },
  },
  props: {
    parentComment: {
      type: Object,
      // 默认是空数组
      default: {},
    },
  },
  data() {
    return {
      comments: {},
    };
  },
  mounted() {},
  watch: {},
  methods: {
    handlerReply(repid, nickname) {
      let repObj = { repid, nickname };
      this.$emit("sendReply", repObj);
    },
  },
};
</script>

<style lang="less" scoped>
// 评论内容
.comment_content {
  border: 1px solid #e3e3e3;
  margin-left: 5px;
  margin-bottom: 15px;
  padding: 20px 20px 5px;
  background-color: #f9f9f9;
  .comment_writer {
    height: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 12px;
    .writer {
      height: 16px;
      display: flex;
      align-items: center;
      color: #666;
      .date {
        color: #999;
        margin: 0 5px;
      }
      .time {
        color: #999;
      }
    }
  }
  .post_comment_content {
    overflow: hidden;
    // 鼠标移入显示回复按钮
    &:hover .button {
      visibility: visible;
    }
    // padding-left: 30px;
    .img {
      width: 103px;
      height: 103px;
      display: flex;
      // align-items: center;
      // justify-content: center;
      margin-top: 10px;
      .imgItem {
        border: 1px dashed #dddddd;
        border-radius: 5px;
        padding: 5px;
        margin-left: 5px;
      }
      img {
        width: 90px;
        height: 90px;
        object-fit: cover;
      }
    }
    .button {
      cursor: pointer;
      color: #1e50b5;
      height: 20px;
      display: flex;
      align-items: center;
      // justify-content: flex-end;
      float: right;
      font-size: 12px;
      visibility: hidden;
    }
  }
}
</style>